package com.huifaapp.mall.activity.Homefragment;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.ApplicationsRecordAdapter;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.ReturnafterBean;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

public class ReturnafterActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    ReturnafterBean returnafterBean111;
    private List<ReturnafterBean.DataBean> list;
    ReturnafterBean.DataBean dataBean;
    private ReturnafterBean.DataBean.GoodBean goodBean;
    private ImageView iv_returnaftersale_back;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_returnafter);

        initView();

        initData();
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.returnafter_recy);
        iv_returnaftersale_back= (ImageView) findViewById(R.id.iv_returnaftersale_back);
        iv_returnaftersale_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    private void initData() {
        Log.e("售后列表url------------",ApiManager.BASE_NIUPAI_URL+"orders/afterSale/list?token="+SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+AUniqueIdentifier.getDeviceId(ReturnafterActivity.this));

        OkHttpUtils.get().url(ApiManager.BASE_NIUPAI_URL+"orders/afterSale/list")
                .addParams("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN))
                .addParams("appId", AUniqueIdentifier.getDeviceId(ReturnafterActivity.this))
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Request request, Exception e) {
                        ToastUtils.showShort("获取失败");
                    }

                    @Override
                    public void onResponse(String response) {

                        Log.i("售后列表--------",response);
                        try {
                            Gson gson = new Gson();
                            returnafterBean111 = gson.fromJson(response,ReturnafterBean.class);
                            if(returnafterBean111.getCode().equals("10000")) {
                                final ReturnafterBean returnafterBean = gson.fromJson(response, ReturnafterBean.class);
                                list = returnafterBean.getData();
                                ApplicationsRecordAdapter applicationsRecordAdapter = new ApplicationsRecordAdapter(ReturnafterActivity.this, returnafterBean.getData());
                                recyclerView.setLayoutManager(new LinearLayoutManager(ReturnafterActivity.this));
                                recyclerView.setAdapter(applicationsRecordAdapter);
                            }else{
                                Toast.makeText(ReturnafterActivity.this,returnafterBean111.getMsg(),Toast.LENGTH_SHORT).show();
                            }
                        } catch (Exception e) {
                            Log.e("FH","HHH");
                        }
                    }
                });
    }

}
